package team.se.tms.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import team.se.tms.annotation.Regex;
import team.se.tms.annotation.SpecialCheck;
import team.se.tms.dao.Dao;
import team.se.tms.po.SelectCourseInfo;
import team.se.tms.service.SelectCourseInfoService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
 * 这里是描述
 *
 * @author winkyle
 * @date 2018/12/29
 */
@Slf4j
@Service("SelectCourseInfoServiceImpl")
public class SelectCourseInfoServiceImpl extends BaseServiceImpl implements SelectCourseInfoService{
    @Resource(name = "DaoImpl")
    private Dao dao;
    /**
     * 根据用户id与授课id获取课程成绩
     *
     * @param userId 用户id
     * @param teachCourseId 授课id
     * @return 课程成绩
     * @throws Exception 异常
     * @create on 2018/12/29 by winkyle
     */
    @Override
    public Float getCourseGrade(@SpecialCheck("Pk")String userId, @SpecialCheck("Pk")String teachCourseId) throws Exception {
        return dao.selectOne("SelectCourseInfoMapper.selectCourseGradeByUserIdAndTeachCourseId",getParameterMap("userId",userId,"teachCourseId",teachCourseId));
    }

    /**
     * 课程评分 根据授课id与学生id修改成绩与评语
     * @param stuIds
     * @param scores
     * @param judgements
     * @return
     * @throws Exception
     */
    @Override
    public Boolean modifySelectCourseGrade(String teachCourseId, List<String> stuIds, List<Float> scores, List<String> judgements) throws Exception{

        List<SelectCourseInfo> selectCourseInfos =new ArrayList<>();
        for(int i=0; stuIds.size()>0;i++){
            SelectCourseInfo selectCourseInfo = new SelectCourseInfo();
            selectCourseInfo.setTeachCourseId(teachCourseId);
            selectCourseInfo.setStuId(stuIds.get(i));
            selectCourseInfo.setSelectCourseGrade(scores.get(i));
            selectCourseInfo.setSelectCourseJudgement(judgements.get(i));
            selectCourseInfos.add(selectCourseInfo);
        }
        int count = dao.update("SelectCourseInfoMapper.updateSelectCourseGradeByStuIdsAndTeachCourseId",selectCourseInfos);
        if(count>0){
            return true;
        }
        return false;
    }
}
